package io.renren.modules.member.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.store.entity.vo.FoodDiscountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.member.dao.TStoreMemberRuleDao;
import io.renren.modules.member.entity.TStoreMemberRuleEntity;
import io.renren.modules.member.service.TStoreMemberRuleService;


@Service("tStoreMemberRuleService")
public class TStoreMemberRuleServiceImpl extends ServiceImpl<TStoreMemberRuleDao, TStoreMemberRuleEntity> implements TStoreMemberRuleService {

    @Autowired
    private TStoreMemberRuleDao tStoreMemberRuleDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TStoreMemberRuleEntity> page = this.page(
                new Query<TStoreMemberRuleEntity>().getPage(params),
                new QueryWrapper<TStoreMemberRuleEntity>()
                .eq(params.get("sellerId").equals(""),"sellerId",params.get("sellerId"))
        );

        return new PageUtils(page);
    }

    @Override
    public Page<TStoreMemberRuleEntity> listMemberRule(Map<String, Object> params) {
        Page<FoodDiscountVo> page = new Page<FoodDiscountVo>
                (Long.parseLong((String) params.get("current")),Long.parseLong((String) params.get("size")));
        return tStoreMemberRuleDao.listMemberRule(page,params);
    }

    //积分金额兑换率
    @Override
    public double ExchangeIntegral(Long seller, Long memberTypeId) {
        TStoreMemberRuleEntity rule = this.getOne(new QueryWrapper<TStoreMemberRuleEntity>()
                .select("exchange_amount", "exchange_integral")
                .eq("seller_id", seller)
                .eq("member_type_id", memberTypeId));
        //金额和积分的兑换率
        return rule.getExchangeIntegral()/rule.getExchangeAmount();
    }


}